/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package anotherFrameWork;

/**
 *
 * @author Windows7
 */
public final class line {
    private point a;
    private point b;
    
    private boolean isAPoint;
    
    private float distance;
    
    private float slope;
    
    private float vectorB;
    
    private int Plus;
    
    private float speed;
    
    public line()
    {
        this.a = new point();
        this.b = new point();
        this.distance = 0;
        this.isAPoint = true;
        this.slope = 0;
        this.vectorB = 0;
        this.Plus = 0;
        this.speed = (float) 0.5;
    }
    
    public line(point a, point b)
    {
        this.a = new point(a);
        this.b = new point(b);
        this.distance = this.calDist();
        this.calLinear();
        this.isAPoint();
        this.isPlus();
        this.speed = (float) 0.5;
    }
    
    public line(line c)
    {
        this.a = new point(c.a);
        this.b = new point(c.getB());
        this.distance = c.distance;
        this.isAPoint = c.isAPoint;
        this.slope = c.slope;
        this.vectorB = c.vectorB;
        this.Plus = c.Plus;
        this.speed = c.speed;
    }

    /**
     * @return the a
     */
    public point getA() {
        return a;
    }

    /**
     * @param a the a to set
     */
    public void setA(point a) {
        this.a = a;
    }
    
    
    /**
     * @return the b
     */
    public point getB() {
        return b;
    }

    /**
     * @param b the b to set
     */
    public void setB(point b) {
        this.b = b;
        this.distance = this.calDist();
        this.calLinear();
        this.isAPoint();
        this.isPlus();
        this.speed = (float) 1;
    }
    
    
    public float calDist()
    {
	return (float) Math.sqrt((this.a.getX()-this.getB().getX())*(this.a.getX()-this.getB().getX()) +(this.a.getY()-this.getB().getY())*(this.a.getY()-this.getB().getY()));
    }
    
    public void calLinear()
    {
	this.slope = (this.a.getY() - this.getB().getY())/(this.a.getX() - this.getB().getX());
	this.vectorB = (this.a.getY() - this.slope * this.a.getX());
		
	//System.out.printf("y = %f*x + %f",hsg , c);
    }    

    /**
     * @return the isAPoint
     */
    public boolean isIsAPoint() {
        return isAPoint;
    }

    /**
     * @param isAPoint the isAPoint to set
     */
    public void setIsAPoint(boolean isAPoint) {
        this.isAPoint = isAPoint;
    }

    /**
     * @return the distance
     */
    public float getDistance() {
        return distance;
    }

    /**
     * @param distance the distance to set
     */
    public void setDistance(float distance) {
        this.distance = distance;
    }

    /**
     * @return the slope
     */
    public float getSlope() {
        return slope;
    }

    /**
     * @param slope the slope to set
     */
    public void setSlope(float slope) {
        this.slope = slope;
    }

    /**
     * @return the vectorB
     */
    public float getVectorB() {
        return vectorB;
    }

    /**
     * @param vectorB the vectorB to set
     */
    public void setVectorB(float vectorB) {
        this.vectorB = vectorB;
    }
    
    public void isAPoint()
    {
        if(a.isSamePoint(getB()))
        {
            this.isAPoint = true;
        }
        else
        {
            this.isAPoint = false;
        }
    }

    /**
     * @return the isPlus
     */
    public int getPlus() {
        return Plus;
    }
    
    public void isPlus()
    {
        this.Plus = a.xlargerThan(getB());
    }
    
    public boolean next()
    {
        if(this.Plus != 0)
        {
            a.plusX(-(this.Plus * this.speed));
            a.calSlope(this.slope,this.vectorB);
        }
        else
        {
            a.plusY(-this.speed);
            
        }
        isAPoint();
        return this.isAPoint;
    }

    /**
     * @return the speed
     */
    public float getSpeed() {
        return speed;
    }

    /**
     * @param speed the speed to set
     */
    public void setSpeed(int speed) {
        this.speed = speed;
    }
}
